namespace net.podhola.gtd.finances

import System
import System.Collections
import net.podhola
import net.podhola.gtd

[Castle.ActiveRecord.ActiveRecord]
class EnteredBill(Castle.ActiveRecord.ActiveRecordBase of EnteredBill):
	_id as int	
	[Castle.ActiveRecord.PrimaryKey(Castle.ActiveRecord.PrimaryKeyType.Increment)]
	Id as int:
		get: return _id
		set: _id = value

	_subject as string	
	[Castle.ActiveRecord.Property] 
	Subject as string:
		get: return _subject
		set: _subject = value
	
	_expectedPaymentDate as DateTime
	[Castle.ActiveRecord.Property] 
	ExpectedPaymentDate as DateTime:
		get: return _expectedPaymentDate
		set: _expectedPaymentDate = value

	_plannedAccount as Account
	[Castle.ActiveRecord.BelongsTo("accountid")] 
	PlannedAccount as Account:
		get: return _plannedAccount
		set: _plannedAccount = value

	_completed as bool		
	[Castle.ActiveRecord.Property] 
	Completed as bool:
		get: return _completed
		set: _completed = value

	_expenses as IList = ArrayList()
	[Castle.ActiveRecord.HasMany(Expense) ] 
	Expenses as IList:
		get: return _expenses
		set: _expenses = value
		
	_plannedAmount as double
	[Castle.ActiveRecord.Property] 
	PlannedAmount as double:
		get: return _plannedAmount
		set: _plannedAmount = value
		
	def GetAlreadyPaied():
		result = 0.0
		for expense as Expense in Expenses:
			result += expense.Amount
		return result

	def Pay( amount as double, payiedDate as Nullable of DateTime, fromAccount as Account ):
		paiedBill = Expense()
		paiedBill.HasPayedBill = self
		paiedBill.Amount = amount
		paiedBill.FromAccount = fromAccount
		paiedBill.SpentOn = DateTime.Now
		paiedBill.Subject = Subject
